using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;

namespace OrbitOne.CRMLyncInfoDashboard.CRM.OData
{
    [Export(typeof(ICrmMetadataProviderFactory))]
    public class CrmMetadataProviderFactory : ICrmMetadataProviderFactory
    {
        public IEnumerable<ICrmMetadataProvider> CrmMetadataProviders { get; private set; }

        [ImportingConstructor]
        public CrmMetadataProviderFactory([ImportMany] IEnumerable<ICrmMetadataProvider> metadataProviders)
        {
            CrmMetadataProviders = metadataProviders;
        }

        public ICrmMetadataProvider this[string entityLogicalName]
        {
            get { return CrmMetadataProviders.First(p => p.GetType().Name.ToLower().Contains(entityLogicalName)); }
        }
    }
}